/**
 * @filename:QuotationDetailServiceImpl 2021-11-09 01:40:37
 * @project com/lwl/blue  V1.0
 * Copyright(c) 2018 <a href=mailto:lanwenliang@yidianlife.com>蓝文良</a> Co. Ltd. 
 * All right reserved. 
 */
package com.lwl.blue.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lwl.blue.commont.base.BaseDataUtil;
import com.lwl.blue.commont.base.JsonResult;
import com.lwl.blue.commont.base.PageParam;
import com.lwl.blue.dao.QuotationDao;
import com.lwl.blue.dao.QuotationDetailDao;
import com.lwl.blue.entity.Quotation;
import com.lwl.blue.entity.QuotationDetail;
import com.lwl.blue.service.FilesService;
import com.lwl.blue.service.QuotationDetailService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**   
 * <p>自定义serviceImpl写在这里</p>
 * 
 * <p>说明： 报价单明细服务实现层</P>
 * @version: V1.0
 * @author: <a href=mailto:lanwenliang@yidianlife.com>蓝文良</a>
 * 
 */
@Service
public class QuotationDetailServiceImpl  extends ServiceImpl<QuotationDetailDao, QuotationDetail> implements QuotationDetailService  {
    @Resource
    private  QuotationDetailDao quotationDetailDao;
    @Resource
    FilesService filesService;
    @Resource
    private QuotationDao quotationDao;
    @Override
    public JsonResult<Page<QuotationDetail>> pages(PageParam<QuotationDetail> pageParam) {
        Page<QuotationDetail> page = new Page<>(pageParam.getPageNum(), pageParam.getPageSize());
        return new JsonResult<Page<QuotationDetail>>().success(quotationDetailDao.pages(page, pageParam.getParam()));
    }

    @Override
    public List<QuotationDetail> getExportList(QuotationDetail quotation) {
        if(!org.springframework.util.CollectionUtils.isEmpty(quotation.getIdBatch())){
            List<Integer> idBatch = quotation.getIdBatch();
            quotation=new QuotationDetail();
            quotation.setIdBatch(idBatch);
        }
        return quotationDetailDao.pages(quotation);
    }

    @Override
    public JsonResult saveUpdateData(QuotationDetail quotationDetail) {
        BaseDataUtil.setInsetOrUpdateUser(quotationDetail);
        QuotationDetail old = null;
        if (Objects.nonNull(quotationDetail.getId())) {
            old = this.getById(quotationDetail.getId());
        }
        this.saveOrUpdate(quotationDetail);
        filesService.updateBySaveOrUpdate(quotationDetail.getPhoto(), Objects.isNull(old) ? null : old.getPhoto(), quotationDetail.getId(), quotationDetail.getItemNo());
//        Quotation quotation = quotationDao.selectById(quotationDetail.getQuotationId());
//        quotationDao.updateById(quotation);
        return new JsonResult().success("请求成功");
    }
}